<!DOCTYPE html>
<html lang="zh-CN" xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head th:include="/common/inc::header"/>
<body>
<form class="layui-form" style="margin-top: 15px">
    <div class="layui-form-item">
        <label class="layui-form-label" style="width: 60px">标题:</label>
        <div class="layui-input-inline">
            <input type="text" name="title" id="title" autocomplete="off"
                   class="layui-input">
        </div>
        <label class="layui-form-label" style="width: 40px">类别:</label>
        <div class="layui-input-inline">
            <select name="sortId" id="sortId">
                <option value="">全部</option>
                <option value="0">首页banner</option>
                <option value="1">首页小图</option>
                <option value="2">预定指南</option>
                <option value="3">空房推荐</option>
            </select>
        </div>
        <button class="layui-btn" id="searchBtn" lay-submit lay-filter="searchBtn">查询</button>
        <button class="layui-btn" lay-submit lay-filter="addBtn" id="addBtn">新增首页广告</button>
    </div>
</form>
<table class="layui-table" id="grid" lay-filter="grid">
</table>
<script th:replace="/common/inc::incJs"></script>
<script>
    var btnRight;
    var tableIns;
    var isSuper = 0;

    $(function () {
        tableIns = createTable({
            url: 'list',
            cols: [[{field: 'id', title: '编号', width: 60},
                {field: 'title', title: '标题', width: 120}
                , {field: 'linkurl', title: '外链地址', width: 500}, {
                    field: 'sortId',
                    title: '类型',
                    width: 240,
                    templet: '#sortTpl'
                }, {
                    fixed: 'right',
                    title: '操作',
                    width: 200,
                    align: 'center',
                    toolbar: '#opbar'
                }
            ]]
        });
    });

    layui.table.on('tool(grid)', function (obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
        var data = obj.data; //获得当前行数据
        var layEvent = obj.event; //获得 lay-event 对应的值
        var tr = obj.tr; //获得当前行 tr 的DOM对象02\
        if (layEvent === 'change') { //删除
            changeStatus(data.id, data.delBoolean);
        } else if (layEvent === 'edit') { //编辑
            openDialog({
                url: "/backend/security/news/detail?id=" + data.id,
                area: ["70%", "80%"]
            });
        } else if (layEvent === 'del') { //删除
            delRecord("/backend/security/news/del", obj)
        }
    });


    layui.form.on('submit(addBtn)', function () {
        openDialog({
            url: "/backend/security/news/detail",
            area: ["70%", "80%"]
        });
        return false;
    });

    layui.form.on('submit(searchBtn)', function (data) {
        tableIns.reload({
            where: data.field
        });
        return false;
    });

</script>

<script type="text/html" id="sortTpl">
    {{# if(d.sortId===0){ }}
    <span>首页banner</span>
    {{#  } else if(d.sortId===1){ }}
    <span>首页小图</span>
    {{#  }  }}
</script>
<script type="text/html" id="opbar">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
</body>
</html>
